<?php
session_start();
if (isset($_POST['username'])==true){	
	require_once("../classDB.php");
	$db = new db();  
	$username = $_POST['username'];
	$password = md5($_POST['password']);
	if (get_magic_quotes_gpc()== false) {
		$username=trim(mysql_real_escape_string($username));
		$password=trim(mysql_real_escape_string($password));
	}
	$sql = "SELECT * FROM users WHERE username='$username' AND password ='$password'";
	$user = mysql_query($sql);
	if (mysql_num_rows($user)==1) {//Thành công	
if (isset($_POST['nho'])== true){
	 setcookie("un", $_POST['username'], time() + 60*60*24*7 );
	 setcookie("pw", $_POST['password'], time() + 60*60*24*7 );
} else {
	 setcookie("un", $_POST['username'], time() -1);
	 setcookie("pw", $_POST['password'], time() -1);
}
$row_user = mysql_fetch_assoc($user);
$_SESSION['kt_login_id'] = $row_user['idUser'];
$_SESSION['kt_login_user'] = $row_user['Username'];
$_SESSION['kt_login_level'] = $row_user['idGroup'];
$_SESSION['kt_HoTen'] = $row_user['HoTen'];
$_SESSION['kt_GioiTinh'] = $row_user['GioiTinh'];
if (strlen($_SESSION['back'])>0){
	$back = $_SESSION['back']; unset($_SESSION['back']);
	//header("location:$back");
} else header("location: index.php");
	} else { //Thất bại
   // header("location: login.php");
  }
}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="../../assets/ico/favicon.ico">
    <title>Login</title>
    <!-- Bootstrap core CSS -->
    <link href="../css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="../css/signin.css" rel="stylesheet">
    <script src="../js/jquery-1.9.1.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <div class="container">
    <div style="display:none;width: 500px; margin: auto;" class="alert alert-danger">Vui lòng đăng nhập
    <script type="text/javascript">
	$(function() {
		$('.alert').fadeIn(500).delay(2000).fadeOut(500);
	});			
    </script>
    </div>
      <form class="form-signin" role="form" method="post" action="" autocomplete="on" >
        <h2 class="form-signin-heading">Login</h2>
        <input type="text" name="username" id="username" class="form-control" placeholder="Tên đăng nhập" required autofocus>
        <input type="password" name="password" id="password" class="form-control" placeholder="Mật khẩu" required>
        <label class="checkbox">
          <input type="checkbox" value="remember-me"> Remember me
        </label>
        <button class="btn btn-lg btn-primary btn-block" type="submit" >Đăng nhập</button>
        
      </form>
    </div> <!-- /container -->
    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
  </body>
</html>
